package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.TransferAccountInfoAddDTO;
import org.jsola.hr.dto.TransferAccountInfoUpdateDTO;
import org.jsola.hr.entity.TransferAccountInfoDO;
import org.jsola.hr.query.TransferAccountInfoQuery;
import org.jsola.hr.service.ITransferAccountInfoService;
import org.jsola.hr.vo.TransferAccountInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 转账账户库
 *
 * @author zhr
 */
@Component
public class TransferAccountInfoTestHelper extends BaseTestHelper {
    
    @Autowired
    private ITransferAccountInfoService transferAccountInfoService;

    /**
     * 生成add测试数据
     * @return TransferAccountInfoAddDTO
     */
    public TransferAccountInfoAddDTO getTransferAccountInfoAddDTO(){
        TransferAccountInfoAddDTO transferAccountInfoAddDTO = new TransferAccountInfoAddDTO();
        transferAccountInfoAddDTO.setName(getRandomValue("varchar",20));
        transferAccountInfoAddDTO.setPhone(getRandomValue("varchar",20));
        transferAccountInfoAddDTO.setZfbLoginId(getRandomValue("varchar",64));
        transferAccountInfoAddDTO.setZfbPid(getRandomValue("varchar",200));
        transferAccountInfoAddDTO.setZfbToken(getRandomValue("varchar",500));
        transferAccountInfoAddDTO.setZfbAccountBookId(getRandomValue("varchar",20));
        transferAccountInfoAddDTO.setSubMchid(getRandomValue("varchar",500));
        transferAccountInfoAddDTO.setBankAccountId(getRandomValue("varchar",500));
        transferAccountInfoAddDTO.setCompanyCode(getRandomValue("varchar",50));
        transferAccountInfoAddDTO.setAgreeNo(getRandomValue("varchar",50));
        transferAccountInfoAddDTO.setBusiType(getRandomValue("varchar",50));
        transferAccountInfoAddDTO.setType(SafeKit.getInteger(getRandomValue("int",4)));
        transferAccountInfoAddDTO.setMoney(SafeKit.getBigDecimal(getRandomValue("decimal",20)));
        transferAccountInfoAddDTO.setSiteName(getRandomValue("varchar",50));
        return transferAccountInfoAddDTO;
    }


    /**
     * 生成update测试数据
     * @return TransferAccountInfoUpdateDTO
     */
    public TransferAccountInfoUpdateDTO getTransferAccountInfoUpdateDTO(TransferAccountInfoVO transferAccountInfoVO){
        return transferAccountInfoService.selectDOById(transferAccountInfoVO.getId(), SITE_ID).to(TransferAccountInfoUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return TransferAccountInfoQuery
     */
    public TransferAccountInfoQuery getTransferAccountInfoQuery() {
        TransferAccountInfoQuery transferAccountInfoQuery = new TransferAccountInfoQuery();
        List<TransferAccountInfoDO> transferAccountInfoDOList = transferAccountInfoService.list(new TransferAccountInfoDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(transferAccountInfoDOList)) {
            TransferAccountInfoDO transferAccountInfoDO = transferAccountInfoDOList.get(0);
            transferAccountInfoQuery = transferAccountInfoDO.to(TransferAccountInfoQuery.class);
        }
        return transferAccountInfoQuery;
    }

    /**
     * 保存示例
     * @return TransferAccountInfoVO
     */
    public TransferAccountInfoVO saveTransferAccountInfoExample(){
        TransferAccountInfoAddDTO addDTO = this.getTransferAccountInfoAddDTO();
        TransferAccountInfoVO transferAccountInfoVO = transferAccountInfoService.save(addDTO,buildTokenUser());
        return transferAccountInfoVO;
    }


}

